//
// Created by user on 2022/3/9.
//
#include <vector>
#include <unordered_map>
using namespace std;
int majorityElement(vector<int>& nums) {
    unordered_map<int, int> counts;
    int majority = 0, cnt = 0;
    for (int num: nums) {
        ++counts[num];
        if (counts[num] > cnt) {
            majority = num;
            cnt = counts[num];
        }
    }
    return majority;
}